package search.eightpuzzle.astar;

import search.eightpuzzle.model.PuzzleState;

import java.util.function.ToDoubleBiFunction;

/**
 * Created by Ponteleev on 2/1/2015.
 */
public class DwaStar extends AStar {
    private int N = 5;
    private double epsilon = 1. / 4.;

    public DwaStar(PuzzleState start, PuzzleState goal, Heuristic heuristic) {
        super(start, goal, heuristic);
    }

    @Override
    protected ToDoubleBiFunction<Double, PuzzleState> getEstimatedCostFunction() {

        return (currentCost, puzzleState) ->
                currentCost +
                        (1 + (1 - Math.min(N, puzzleState.getDepth()) / N) * epsilon)
                                * getHeuristic().estimate(puzzleState, getGoal());

    }

    public int getAnticipatedDepthOfDesiredNode() {
        return N;
    }

    public void setAnticipatedDepthOfDesiredNode(int anticipatedDepthOfDesiredNode) {
        this.N = anticipatedDepthOfDesiredNode;
    }

    public double getEpsilon() {
        return epsilon;
    }

    public void setEpsilon(double epsilon) {
        this.epsilon = epsilon;
    }
}
